package outil;

public class TantQueEtSi implements Action {

    private final Predicat pPredicat;
    private final Predicat pActionPredicat;
    private final Action pActionBoucle;
    private final Action pSiAlorsAction;


    public final static Action instance(Predicat pPredicat, Predicat pActionPredicat, Action pAction, Action pActionBoucle) {
        return new TantQueEtSi(pPredicat, pActionPredicat, pAction, pActionBoucle);
    }

    private TantQueEtSi(Predicat pPredicat, Predicat pActionPredicat, Action pAction, Action pActionBoucle) {
        this.pPredicat = pPredicat;
        this.pActionPredicat = pActionPredicat;
        this.pSiAlorsAction = Si.instance(pActionPredicat, pAction, AucuneAction.instance());
        this.pActionBoucle = pActionBoucle;

    }

    @Override
    public void exec() {
        while (pPredicat.eval()) {
            pSiAlorsAction.exec();           
            pActionBoucle.exec();
        }
    }
}
